#include "StompedReality/Asset/FontManager.h"
#include <iostream>
namespace StompedReality
{
namespace Graphics
{
FontManager::FontManager( ) :
  StompedReality::GameAccess( )
{
  this->_defaultFont = 0;
}

FontManager::~FontManager( )
{
}

uint64_t FontManager::createKey( const char* font, int size ) {
  return this->createKey( StompedReality::hash( font ), size );
}

uint64_t FontManager::createKey( StompedReality::ID id, int size ) {
  uint64_t key = id;
  key <<=32;
  key |= size;
  return key;
}

void FontManager::createFont ( const char* font, int size )
{
  if (this->getFont( font, size ) != -1) {
    return;
  }
  int fontList = this->loadFont ( font, size );
  if (this->_fontMap.empty( )) {
    this->_defaultFont = fontList;
  }
  this->_fontMap[ createKey( font, size ) ] = fontList;
}

int FontManager::getFont( StompedReality::ID id, int size ) {
  FontMap::iterator iter = this->_fontMap.find( this->createKey( id, size ) );
  if (iter == this->_fontMap.end( )) {
    return -1;
  }
  return iter->second;
}

int FontManager::getFont ( const char* font, int size )
{
  return this->getFont( StompedReality::hash( font ), size );
}

void FontManager::selectFont( const char* name, int size )
{
  this->selectFont( StompedReality::hash( name ), size );
}

bool FontManager::hasFont( const char* font, int size )
{
  return this->hasFont( StompedReality::hash( font ), size );
}

bool FontManager::hasFont( StompedReality::ID id, int size )
{
  return this->_fontMap.find( this->createKey( id, size ) ) != this->_fontMap.end( );
}

}
}
